<?php

namespace Biz;

use Aliyun\Ecs\Request\V20140526 as Ecs;
use Aliyun\Core\DefaultAcsClient;
use Mts\Request\V20140618\SubmitSnapshotJobRequest;
use Mts\Request\V20140618\QueryMediaListByURLRequest;
use Mts\Request\V20140618\QueryMediaListRequest;

use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request;


class AliyunMts
{
    private $vhost;
    private $appName;
    private $privateKey;
    private $accessKey;
    private $accessSecret;

    public function __construct($config)
    {
        $this->vhost = $config['host'];
        $this->appName = $config['app_name'];
        $this->accessKey = $config['access_key'];
        $this->accessSecret = $config['access_secret'];
        $this->privateKey = $config['private_key'];
    }

    public function queryMediaListByURL($ossUrl)
    {
        vendor('aliyun-openapi-php-sdk/aliyun-php-sdk-core/Config');
        \Autoloader::addAutoloadPath('aliyun-php-sdk-mts');
        $iClientProfile = \DefaultProfile::getProfile('cn-shenzhen', $this->accessKey, $this->accessSecret);
        $client = new \DefaultAcsClient($iClientProfile);
        $request = new QueryMediaListByURLRequest();
        $request->setFileURLs($ossUrl);
        $response = $client->getAcsResponse($request);
        return $response;
    }

    /**
     * 根据mediaId查询媒体库
     *
     * @param string $mediaId
     * @return void
     */
    public function queryMediaList($mediaId)
    {
        vendor('aliyun-openapi-php-sdk/aliyun-php-sdk-core/Config');
        \Autoloader::addAutoloadPath('aliyun-php-sdk-mts');
        $iClientProfile = \DefaultProfile::getProfile('cn-shenzhen', $this->accessKey, $this->accessSecret);
        $client = new \DefaultAcsClient($iClientProfile);
        $request = new QueryMediaListRequest();
        $request->setMediaIds($mediaId);
        $response = $client->getAcsResponse($request);
        return $response;
    }

    public function submitSnapshotJob()
    {
        vendor('aliyun-openapi-php-sdk/aliyun-php-sdk-core/Config');
        \Autoloader::addAutoloadPath('aliyun-php-sdk-mts');
        $iClientProfile = \DefaultProfile::getProfile('cn-shanghai', $this->accessKey, $this->accessSecret);
        $client = new \DefaultAcsClient($iClientProfile);
        $request = new SubmitSnapshotJobRequest();
        $input = [
            'Bucket' => 'cywbucket',
            'Location' => 'oss-cn-shenzhen',
            'Object' => 'microvideos/20170808/427ccc5b69874f37468e94578f700f57.mp4'
        ];
        $snapshotConfig = [
            'OutputFile' => [
                'Bucket' => 'cywbucket',
                'Location' => 'oss-cn-shanghai',
                'Object' => 'example.jpg'
            ],
            'Time' => '5',
        ];

        $request->setInput(json_encode($input));
        $request->setSnapshotConfig(json_encode($snapshotConfig));
        // $request->setStreamName('15_060275_0624');
        $response = $client->getAcsResponse($request);
        dump($response);

    }

    
}
